package com.Iron.MyComponent;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class MyComponentBeanFactory implements BeanDefinitionRegistryPostProcessor {

    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        Map<String, Class> stringClassMap = BaseClassScanUtils.scanMyComponentAnnotation("com.Iron");

        stringClassMap.forEach((a,b)->{
            System.out.println(b.getName());
            BeanDefinition beanDefinition = new RootBeanDefinition();
            beanDefinition.setBeanClassName(b.getName());
            registry.registerBeanDefinition(b.getName(), beanDefinition);
        });
    }

    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    }
}
